package cn.usain.controller;

import cn.jiyun.pojo.Orders;
import cn.usain.mapper.OrdersMapper;
import cn.usain.service.OrdersService;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import org.bouncycastle.jcajce.util.DefaultJcaJceHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/orders")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @Autowired
    private OrdersMapper ordersMapper;
    @GetMapping("/daily-platform-earnings")
    public Map<String, Object> getDailyPlatformEarnings() {
        Map<String, Object> result = new HashMap<>();
        List<String> dates = new ArrayList<>();
        List<BigDecimal> earningsList = new ArrayList<>();

        List<Map<String, Object>> earningsData = ordersMapper.getDailyPlatformEarnings();
        for (Map<String, Object> data : earningsData) {
            dates.add(data.get("date").toString());
            earningsList.add((BigDecimal) data.get("earnings"));
        }
        result.put("dates", dates);
        result.put("earnings", earningsList);
        return result;
    }
    
    @PostMapping("/daily")
    public Map<String, Object> getDailyPlatformEarnings(@RequestBody Map<String, Object> queryParams) {
        Map<String, Object> result = new HashMap<>();
        List<String> dates = new ArrayList<>();
        List<BigDecimal> earningsList = new ArrayList<>();

        List<Map<String, Object>> earningsData = ordersMapper.getPlatformEarnings(queryParams);
        for (Map<String, Object> data : earningsData) {
            dates.add(data.get("date").toString());
            earningsList.add((BigDecimal) data.get("earnings"));
        }

        result.put("dates", dates);
        result.put("earnings", earningsList);
        return result;
    }
}
